import { mutableHandlers, readonlyHandlers } from "./basehandler";

export const enum ReactiveFlags {
  IS_REACTIVE = "__v_is_reactive",
  IS_READONLY = "__v_is_readonly",
}

function createActiveObject(raw: any, baseHandler: any) {
  return new Proxy(raw, baseHandler);
}

export function reactive(raw: any) {
  return createActiveObject(raw, mutableHandlers);
}

export function readonly(raw: any) {
  return createActiveObject(raw, readonlyHandlers);
}

export function isReactive(value: any) {
  // 将不是reactive的值转换Boolean
  return !!value[ReactiveFlags.IS_REACTIVE];
}

export function isReadonly(value: any) {
  // 将不是reactive的值转换Boolean
  return !!value[ReactiveFlags.IS_READONLY];
}
